package servlet;

import java.io.IOException;
import java.sql.Connection;
import java.util.HashSet;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;

import pojo.Book;
import pojo.Orders;
import pojo.User;
import service.BookManager;
import service.impl.BookmanagerFactory;
import util.DButil;

/**
 * Servlet implementation class BookShowServlet
 */
public class BookShowServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private BookManager manager;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BookShowServlet() {
        super();
        manager=BookmanagerFactory.getInstance();
    }


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		DataSource ds=(DataSource)request.getServletContext().getAttribute("ds");
		Connection con=DButil.getConnection(ds);		
		List<Book> books=manager.getAllBooks(con);
		request.setAttribute("books", books);
		HashSet<Orders> oSet=(HashSet<Orders>)request.getSession().getAttribute("oset");
		request.setAttribute("oset", oSet);
		
		System.out.println(oSet.size());
		
		request.getRequestDispatcher("list.jsp").forward(request, response);
		DButil.close(con);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
		
	}

}
